package org.example.coupon.controller;

import java.util.List;
import java.util.Map;

import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.example.coupon.bo.SeckillSkuRelationBo;
import org.example.coupon.to.SkuSeckillTo;
import org.example.coupon.vo.SeckillSkuRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.example.coupon.entity.SeckillSkuRelationEntity;
import org.example.coupon.service.SeckillSkuRelationService;



/**
 * @author xiaojie_cc
 * @version 1.0
 */
@RestController
@RequestMapping("sms/backend/sRelation")
public class SeckillSkuRelationController {
    @Autowired
    private SeckillSkuRelationService seckillSkuRelationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<?> list(@RequestParam("pageNum") Integer pageNum
            ,@RequestParam("pageSize") Integer pageSize
            ,@RequestParam("promotionId") Long promotionId
            ,@RequestParam("sessionId") Long sessionId) {
        PageUtils pageUtils = seckillSkuRelationService.getSkuRelationList(pageNum, pageSize, promotionId, sessionId);
        return R.ok(pageUtils);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R<?> info(@PathVariable("id") Long id){

        return null;
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@RequestBody SeckillSkuRelationBo seckillSkuRelationBo){
        return seckillSkuRelationService.addSeckillSkuRelation(seckillSkuRelationBo)>0? R.ok():R.error();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody SeckillSkuRelationEntity seckillSkuRelation){
        seckillSkuRelationService.update(seckillSkuRelation);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody List<Long> ids){
        seckillSkuRelationService.delete(ids);
        return R.ok();
    }

    /**
     * 秒杀查询商品信息
     * @return
     */
    @GetMapping("/regular/seckill")
    public R<?> regularSeckill(){
        List<SkuSeckillTo> entities = seckillSkuRelationService.regularSeckill();
        return R.ok(entities);
    }
}
